using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace OpenRay
{
	public class CompositeMaterial : Material
	{
		private readonly IList<Material> materials;
		private readonly InterpolationData data;
		
		public CompositeMaterial (IList<Material> m, InterpolationData d)
		{
			Debug.Assert( m.Count == 3 );
			
			materials = m;
			data = d;
		}
		
		public override Color Shade( Point worldHit, Point ModelHit, Vector normalizedViewer, Vector surfaceNormal, IList<Light> lights, uint depth )
		{
			Material.Face f = FaceHit(normalizedViewer, surfaceNormal);
			
			return materials[0].Shade(worldHit, ModelHit, normalizedViewer, surfaceNormal, lights, f, depth) * data[0] +
				   materials[1].Shade(worldHit, ModelHit, normalizedViewer, surfaceNormal, lights, f, depth) * data[1] +
				   materials[2].Shade(worldHit, ModelHit, normalizedViewer, surfaceNormal, lights, f, depth) * data[2];	
		}
		
		public override Color Shade( Point worldHit, Point ModelHit, Vector normalizedViewer, Vector surfaceNormal, IList<Light> lights, Material.Face f, uint depth )
		{
			return materials[0].Shade(worldHit, ModelHit, normalizedViewer, surfaceNormal, lights, f, depth) * data[0] +
				   materials[1].Shade(worldHit, ModelHit, normalizedViewer, surfaceNormal, lights, f, depth) * data[1] +
				   materials[2].Shade(worldHit, ModelHit, normalizedViewer, surfaceNormal, lights, f, depth) * data[2];
		}
	}
}

